<template>
  <div>
    <van-uploader v-model="fileList" :after-read="afterRead" />
  </div>
</template>
<script>
import {uploadFile} from '@/api/index'
export default{
  data () {
    return {
      fileList:[]
    }
  },
  methods:{
    afterRead(file) {
      // 此时可以自行将文件上传至服务器
      console.log(file);
      
      let formData = new FormData();
      formData.append('img',file.file);    
      this.upImg(formData)
    },
    async upImg (file) {
      // const res = await axios.post('/api/upload/img',file),
      //可以使用原生axios提交数据，解决数据提交问题
      //const res = await uploadFile(file)
      const res = await uploadFile(file)
      if(res.status === 200) {
        console.log(res)
        this.$toast(res.msg)  
      }else{
        this.$toast(res.msg)  
      }
    },
  }
}
</script>
<style lang='less' scoped>
</style>